package com.ruoyi.zhgd.controller;

import java.util.List;
import java.util.Arrays;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.zhgd.domain.bo.NAsphaltAlarmHandlerEditBo;
import com.ruoyi.zhgd.domain.vo.NAsphaltAlarmCountVo;
import com.ruoyi.zhgd.domain.vo.NAsphaltAlarmHandlerVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.NAsphaltAlarmVo;
import com.ruoyi.zhgd.domain.bo.NAsphaltAlarmBo;
import com.ruoyi.zhgd.service.INAsphaltAlarmService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 沥青拌合站筛孔数据
 *
 * @author zyb
 * @date 2023-09-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/asphaltAlarm")
public class NAsphaltAlarmController extends BaseController {

    private final INAsphaltAlarmService iNAsphaltAlarmService;

    /**
     * 查询沥青拌合站筛孔数据列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<NAsphaltAlarmVo> list(NAsphaltAlarmBo bo, PageQuery pageQuery) {
        return iNAsphaltAlarmService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出沥青拌合站筛孔数据列表
     */
    @SaCheckLogin
    @Log(title = "沥青拌合站筛孔数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NAsphaltAlarmBo bo, HttpServletResponse response) {
        List<NAsphaltAlarmVo> list = iNAsphaltAlarmService.queryList(bo);
        ExcelUtil.exportExcel(list, "沥青拌合站筛孔数据", NAsphaltAlarmVo.class, response);
    }

    /**
     * 获取沥青拌合站筛孔数据详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<NAsphaltAlarmVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iNAsphaltAlarmService.queryById(id));
    }

    /**
     * 新增沥青拌合站筛孔数据
     */
    @SaCheckLogin
    @Log(title = "沥青拌合站筛孔数据", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NAsphaltAlarmBo bo) {
        return toAjax(iNAsphaltAlarmService.insertByBo(bo));
    }

    /**
     * 修改沥青拌合站筛孔数据
     */
    @SaCheckLogin
    @Log(title = "沥青拌合站筛孔数据", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NAsphaltAlarmBo bo) {
        return toAjax(iNAsphaltAlarmService.updateByBo(bo));
    }

    /**
     * 删除沥青拌合站筛孔数据
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "沥青拌合站筛孔数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iNAsphaltAlarmService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 获取沥青预警分页列表
     */
    @SaCheckLogin
    @GetMapping("/page")
    public TableDataInfo<NAsphaltAlarmVo> page(NAsphaltAlarmBo bo, PageQuery pageQuery) {
        return iNAsphaltAlarmService.page(bo, pageQuery);
    }

    /**
     * 统计预警信息
     */
    @SaCheckLogin
    @GetMapping("/count")
    public R<NAsphaltAlarmCountVo> count(NAsphaltAlarmBo bo) {
        return R.ok(iNAsphaltAlarmService.count(bo));
    }

    /**
     * 预警处理
     */
    @SaCheckLogin
    @GetMapping("/handler/{id}")
    public R<NAsphaltAlarmHandlerVo> handler(@PathVariable("id") String id) {
        NAsphaltAlarmHandlerVo data = iNAsphaltAlarmService.handler(id);
        if (ObjectUtils.isEmpty(data)) {
            throw new ServiceException("预警信息不存在");
        } else {
            return R.ok(data);
        }
    }

    /**
     * 预警处理
     * @param bo
     * @return
     */
    @SaCheckLogin
    @PostMapping("/handlerEdit")
    public R<String> handlerEdit(@RequestBody @Validated NAsphaltAlarmHandlerEditBo bo) {
        iNAsphaltAlarmService.handlerEdit(bo);
        return R.ok();
    }

}
